package com.example.memo1.activity;

import static com.example.memo1.R.id.find;
import static com.example.memo1.R.id.first;
import static com.google.android.material.bottomnavigation.BottomNavigationView.*;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentTransaction;

import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.example.memo1.R;
import com.example.memo1.adapter.RecordAdapter;
import com.example.memo1.bean.Record;
import com.example.memo1.dao.AdminDao;
import com.example.memo1.util.DBUtil;
import com.getbase.floatingactionbutton.FloatingActionButton;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
private FloatingActionButton fab;
private Button first;
    private Button find;
    private Button mine;


private ListView listView;
    RecordAdapter adapter;
    List<Record> originalItems;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//连接数据库
        DBUtil dbUtil =new DBUtil(MainActivity.this);
        SQLiteDatabase db=dbUtil.getWritableDatabase();
        DBUtil.db=db;




        fab=findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent =new Intent(MainActivity.this, Add.class);
                startActivity(intent);

            }
        });

        first=findViewById(R.id.first);
        first.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent1 =new Intent(MainActivity.this, MainActivity.class);
                startActivity(intent1);

            }
        });
        find=findViewById(R.id.find);
        find.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent2 =new Intent(MainActivity.this, FindActivity.class);
                startActivity(intent2);

            }
        });
        mine=findViewById(R.id.mine);
        mine.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent3 =new Intent(MainActivity.this, MineActivity.class);
                startActivity(intent3);

            }
        });




        //加载列表
        listView=findViewById(R.id.show_id);
        //列表读取数据
         originalItems=new ArrayList<>();//全局列表
        originalItems=new AdminDao().showRecord();
        if(originalItems.size()==0){
            listView.setAdapter(null);//界面什么都没有
        }else {
             adapter=new RecordAdapter(this,originalItems);
            listView.setAdapter(adapter);

        }





    }



}